package com.h3c.ptability.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.h3c.ptability.cache.UserCache;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author chenyifan
 * @date 2022/5/27 9:07
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createBy", UserCache.getLoginUserNameAndId() ,metaObject);
        this.setFieldValByName("createTime", new Date(),metaObject);
        this.setFieldValByName("updateBy",  UserCache.getLoginUserNameAndId(),metaObject);
        this.setFieldValByName("updateTime", new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateBy",  UserCache.getLoginUserNameAndId(),metaObject);
        this.setFieldValByName("updateTime", new Date(),metaObject);
    }
}
